import { defineConfig, loadEnv, type ConfigEnv } from 'vite'
import { resolve } from 'path'

import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import postcssPxToRem from 'postcss-pxtorem'
// https://vitejs.dev/config/
export default defineConfig((mode: ConfigEnv) => {
  const env = loadEnv(mode.mode, process.cwd())
  return {
    plugins: [vue(), vueJsx()],
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src')
      },
      extensions: ['.ts', '.vue', '.js', '.jsx', '.tsx'] // 导入时想要省略的扩展名列表。
    },

    css: {
      postcss: {
        plugins: [
          postcssPxToRem({
            rootValue: '37.5',
            propList: ['*']
          })
        ]
      }
    },
    server: {
      // proxy: {
      //   '/app-dev': {
      //     target: 'http://gmall-h5-api.atguigu.cn',
      //     changeOrigin: true,
      //     rewrite: (path) => path.replace(/^\/app-dev/, ''),
      //   },
      // }
      proxy: {
        '/app-dev': {
          target: 'http://gmall-h5-api.atguigu.cn',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/app-dev/, '')
        },
        '/wangyi': {
          target: 'https://m.you.163.com',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/wangyi/, '')
        }
      }
    }
  }
})
